// pages/seatSelect/seatSelect.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    timeId:null,
    username:null,
    seats:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var page = this;
    page.setData({username:options.username});
    page.setData({timeId:options.timeId});
    var timeId=this.data.timeId
    var username=this.data.username
    console.log(timeId+"|"+username)
    wx.request({
      url: 'http://127.0.0.1:8080/getSeatInfoByTimeId_wx',
      method:'GET',
      data:{'timeId':timeId},
      header:{
        "Content-Type":"json"
      },
      success:function(res){
         console.log(res);
         var seats = new Array();
         var subjects = res.data.data;
         var len = subjects.length ;
         for(var i=0;i<len;i++){
            var subject = subjects[i];
            var seat = new Object();
            //电影名称
            seat.text = subject.seat_text;
            seat.x = subject.Pos_x;
            seat.y = subject.Pos_y;
            seats.push(seat);

         }
         console.log(seats);
         page.setData({seats:seats});
      }
    })
  },
  seatItem:function(e){
    var x = e.currentTarget.dataset.x
    var y = e.currentTarget.dataset.y
    var timeId=this.data.timeId
    var username=this.data.username
    console.log("timeId:"+timeId+"|username:"+username+"|x:"+x+"|y:"+y)
    wx.request({
      url: 'http://127.0.0.1:8080/createOrder_wx',
      method:'GET',
      data:{"timeId":timeId,"username":username,"x":x,"y":y},
      header:{
        "Content-Type":"json"
      },
      success:function(res){
         console.log(res);
         wx.navigateTo({
          url: '../orderOver/orderOver'
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})